﻿using System;
using System.CommandLine;

namespace DemoCommandLine
{
    internal class Time
    {
        public Time(RootCommand rootCmd)
        {
            var dateTime = new Argument<string>("DateTime", "print DateTime");
            dateTime.SetDefaultValue("");
            var subCom = new Command("time", "print dateTime") {dateTime };
            subCom.SetHandler((datetimeValue) =>
            {
                //DateTime vimTime = DateTime.MinValue;
                //DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0));
                //vimTime = startTime.AddSeconds(timeValue);
                //Console.WriteLine($"{vimTime.ToLocalTime()}");
                var parseDate = DateTime.Now;
                if (datetimeValue.Length > 0) {
                    parseDate = DateTime.Parse(datetimeValue);
                }
                DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                long timeStamp = (long)(parseDate - startTime).TotalSeconds;
                Console.WriteLine($"{timeStamp}");
            }, dateTime);
            rootCmd.Add(subCom);
        }
    }
}
